package com.dynamic.model.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.dynamic.model.common.dao.impl.BaseDaoImpl;
import com.dynamic.model.common.vo.Page;
import com.dynamic.model.dao.SystemUserDao;
import com.dynamic.model.model.po.SysmanUser;
import org.springframework.stereotype.Repository;

/**
 * 
 * @desc 用户后台登陆用户表--RBAC权限管理dao接口实现类
 *
 * @author luwei
 * @Fri Aug 08 14:25:29 CST 2014
 */
@Repository
public class SystemUserDaoImpl extends BaseDaoImpl<SysmanUser> implements SystemUserDao {

	@Override
	public SysmanUser findByName(String userName) {
		String hql = "from "+ this.clazz.getName() + " where userName = ? and deleteFlag=0" ;
		return this.queryForObject(hql, new Object[]{userName});
	}

	@Override
	public List<SysmanUser> getPageDataReqName(Page<SysmanUser> page, String username, String realname, String statu, int currentUserId, int userType) {
		List<Object> prams=new ArrayList<Object>();
		String hql="from SysmanUser t where t.deleteFlag = 0 and t.userType=? and t.pid<>t.creater and t.creater="+currentUserId;
		prams.add(userType);
		if(null!=username&&username.length()>0){
			hql=hql+" and t.userName like ?";
			prams.add("%"+username+"%");
		}
		if(null!=realname&&realname.length()>0){
			hql=hql+" and t.realName=?";
			prams.add(realname);
		}
		if(null!=statu&&statu.length()>0){
			hql=hql+" and t.status=?";
			prams.add(Integer.parseInt(statu));
		}
		hql=hql+" order by t.createTime desc,pid desc";
		return this.queryForList(hql, prams, page );
	}

}
